package com.mall.b2c.controller;

import static com.mall.b2c.Constants.EMAIL_RESEND_TIME;
import static com.mall.b2c.Constants.REDIS_BIND_EMAIL_PREFIX;
import static com.mall.b2c.Constants.REDIS_BIND_SMS_PREFIX;
import static com.mall.b2c.Constants.SMS_RESEND_TIME;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mall.b2c.bean.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mall.b2c.hessian.CardHessian;
import com.mall.b2c.hessian.CommentHessian;
import com.mall.b2c.hessian.IntergralHessian;
import com.mall.b2c.hessian.MemberExtendHessian;
import com.mall.b2c.hessian.TradeHessian;
import com.mall.b2c.util.SerialNumberUtil;
import com.mall.common.bean.Message;
import com.mall.common.enums.FieldType;
import com.mall.common.exception.NoticeException;
import com.mall.common.service.MyCaptchaService;
import com.mall.common.service.RSAService;
import com.mall.common.util.AppContext;
import com.mall.common.util.ResponseUtils;
import com.mall.common.validation.annotation.RequiredFieldValidator;
import com.mall.common.validation.annotation.RequiredStringValidator;
import com.mall.common.validation.annotation.SpecialRegexFieldValidator;
import com.mall.common.validation.annotation.StringLengthFieldValidator;
import com.mall.common.validation.annotation.Validations;

@Controller
@RequestMapping("/member")
public class MemberController extends BaseController {
	@Resource private RSAService rsaService;
	@Resource private MyCaptchaService captchaService;
	@Resource private RedisTemplate<String, String> redisTemplate;
	@Resource private CommentHessian commentHessian;
	@Resource private MemberExtendHessian memberExtendHessian;
	@Resource private TradeHessian tradeHessian;
	@Resource private CardHessian cardHession;
	@Resource private IntergralHessian intergralHession;
	/**
	 * 会员中心首页
	 * @param model
	 * @return
	 */
	@RequestMapping("/index")
	public String index(Model model){
		model.addAttribute("member", getMember());
		model.addAttribute("orderList", jsonToList(tradeHessian.findOrderList(getMemberId(), 5), OrderBean.class));
		model.addAttribute("intergralorderList", jsonToList(intergralHession.getOrderlist(getMemberId(), "createDate asc"),IntergralShopOrderBean.class));
		model.addAttribute("favoriteList", jsonToList(memberHessian.findFavoriteList(getMemberId(), 10), GoodsBean.class));
		return "/member/index";
	}
	
	/**
	 * 我的收藏
	 * @param model
	 * @return
	 */
	@RequestMapping("/favorite")
	public String favorite(Integer pageNumber, Model model){
		String result = memberHessian.getFavoriteGoods(getMemberId(), pageNumber);
		model.addAttribute("pager", jsonToObj(result, Pager.class));
		return "/member/favorite";
	}

	/**
	 * 添加收藏夹
	 * @param goodsIds 商品ids
	 * @return
	 */
	@Validations(
			requiredFields = {
					@RequiredFieldValidator(fieldName="goodsIds",message="商品不存在")
			}
	)
	@RequestMapping(value="/addFavorite",method=RequestMethod.POST)
	@ResponseBody
	public Message addFavorite(Long[] goodsIds){
		memberHessian.addFavoriteGoods(goodsIds, getMemberId());
		return successMessage;
	}
	
	/**
	 * 移出收藏夹
	 * @param goodsIds 商品id
	 * @return
	 */
	@Validations(
			requiredFields = {
					@RequiredFieldValidator(fieldName="goodsIds",message="商品不存在")
			}
	)
	@RequestMapping(value="/deleteFavorite",method=RequestMethod.POST)
	@ResponseBody
	public Message deleteFavorite(Long[] goodsIds){
		memberHessian.deleteFavoriteGoods(goodsIds, getMemberId());
		return successMessage;
	}

	/**
	 * 会员信息
	 * @param model
	 * @return
	 */
	@RequestMapping("/info")
	public String info(Model model){
		model.addAttribute("member", getMember());
		return "/member/info";
	}
	
	/**
	 * 保存会员信息
	 * @param member 会员信息
	 * @return
	 */
	@Validations(
			requiredStrings = {
					@RequiredStringValidator(fieldName="name",message="昵称不能为空")
			}
	)
	@RequestMapping(value="/saveInfo",method=RequestMethod.POST)
	@ResponseBody
	public Message saveInfo(MemberBean member){
		member.setId(getMemberId());
		memberHessian.saveMemberInfo(member);
		return successMessage;
	}
	
	/**
	 * 收货地址列表
	 * @return
	 */
	@RequestMapping("/receiver/list")
	public String receiver(Model model){
		model.addAttribute("receivers", JSON.parseArray(memberHessian.getReceiverList(getMemberId())));
		return "/member/receiver";
	}
	
	@RequestMapping("/card/recharge")
	public String recharge(Model model, HttpServletRequest request, HttpServletResponse response){
		
		return "/member/card";
	}
	

	@RequestMapping(value="/card/cardsubmit", method=RequestMethod.POST)
	@ResponseBody
	public JSONObject cardsubmit(Long account,String password){
		//orderBean.setMemberId(getMemberId());
		JSONObject jObj = new JSONObject();
		try {
			String message = cardHession.cardsubmit(account,password,getMemberId());
			if(message.equals("0")){
				jObj.put("error","兑换失败");
			}else{
				jObj.put("success","兑换成功");
			}
			
		} catch (NoticeException e) {
			jObj.put("error", e.getMessage());
			//jObj.put("showCode", "");
		}
		return jObj;
		
	}
	
	/**
	 * 保存收货地址
	 * @param receiver 收货地址信息
	 * @return
	 */
	@Validations(
			requiredStrings = {
					@RequiredStringValidator(fieldName="name",message="收货人不能为空"),
					@RequiredStringValidator(fieldName="address",message="详细地址不能为空"),
					@RequiredStringValidator(fieldName="contact",message="联系方式不能为空"),
					@RequiredStringValidator(fieldName="areaTree",message="地区不能为空")
			},
			stringLengthFields = {
					@StringLengthFieldValidator(fieldName="name", maxLength= "25", message="收货人不能长度不能大于25"),
					@StringLengthFieldValidator(fieldName="address", maxLength = "50", message="详细地址长度不能大于50")
			},
			specials = {
					@SpecialRegexFieldValidator(fieldName="zipCode",fieldType=FieldType.postCode)
			}
	)
	@RequestMapping(value="/saveReceiver",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> saveReceiver(ReceiverBean receiver){
		Map<String, Object> result = new HashMap<String, Object>();
		if(receiver.getId() == null){
			String json = memberHessian.addReceiver(receiver, getMemberId());
			ReceiverBean receiverBean = jsonToObj(json, ReceiverBean.class);
			result.put("id",receiverBean.getId());
		}else{
			memberHessian.updateReceiver(receiver, getMemberId());
		}
		result.put("type", "success");
		result.put("content", "操作成功");
		return result;
	}
	
	/**
	 * 删除收货地址
	 * @param id 收货地址id
	 * @return
	 */
	@Validations(
			requiredFields = {
					@RequiredFieldValidator(fieldName="id",message="收货地址不存在")
			}
	)
	@RequestMapping(value="/deleteReceiver",method=RequestMethod.POST)
	@ResponseBody
	public Message deleteReceiver(Long id){
		memberHessian.deleteReceiver(id, getMemberId());
		return successMessage;
	}

	/**
	 * 设置默认收货地址
	 * @param id 收货地址id
	 * @return
	 */
	@Validations(
			requiredFields = {
					@RequiredFieldValidator(fieldName="id",message="收货地址不存在")
			}
	)
	@RequestMapping(value="/setDefaultReceiver",method=RequestMethod.POST)
	@ResponseBody
	public Message setDefaultReceiver(Long id){
		memberHessian.setDefaultReceiver(id, getMemberId());
		return successMessage;
	}
	
	/**
	 * 安全中心页面
	 * @param model
	 * @return
	 */
	@RequestMapping("/safe")
	public String safe(Model model){
		MemberBean member = getMember();
		if(member.getEmail() == null){
			String token = SerialNumberUtil.buildTokenSn();
			AppContext.setSessionAttr(token, true);
			model.addAttribute("token", token);
		}
		model.addAttribute("member", member);
		return "/member/safe";
	}

	/**
	 * 修改密码页面
	 * @return
	 */
	@RequestMapping("/password")
	public String password(){
		return "/member/password";
	}

	/**
	 * 修改密码
	 * @param oldPwd 原始密码
	 * @param newPwd 新密码
	 * @return
	 */
	@Validations(
			requiredStrings = {
					@RequiredStringValidator(fieldName="oldPwd",message="旧密码错误"),
					@RequiredStringValidator(fieldName="newPwd",message="新密码错误")
			}
	)
	@RequestMapping(value="/modifyPwd",method=RequestMethod.POST)
	@ResponseBody
	public Message modifyPwd(String oldPwd, String newPwd){
		oldPwd = rsaService.decryptParameter(oldPwd);
		newPwd = rsaService.decryptParameter(newPwd);
		memberHessian.modifyPwd(getMemberId(), oldPwd, newPwd);
		return successMessage;
	}
	
	/**
	 * 已绑定邮箱验证
	 * @param model
	 * @return
	 */
	@RequestMapping("/validEmail")
	public String validEmail(Model model){
		MemberBean member = getMember();
		String email = member.getEmail();
		if(StringUtils.isBlank(email)){
			return "redirect:/member/modifyEmail.jhtml";
		}
		model.addAttribute("email", member.getSafeEmail());
		model.addAttribute("captchaId", UUID.randomUUID().toString());
		
		String[] strs = email.split("@");
		model.addAttribute("emailHost", "http://mail." + strs[1]);
		return "/member/email/step1";
	}

	/**
	 * 发送邮件到已绑定邮箱验证
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/sendValidEmail",method=RequestMethod.POST)
	@ResponseBody
	public Message sendValidEmail(String captchaId, String captcha, String token){
		if(StringUtils.isNotBlank(token) && AppContext.getSessionAttr(token) == null
				|| StringUtils.isBlank(token) && !captchaService.isValid(captchaId, captcha)){
			throw new NoticeException("验证码不正确");
		}
		memberHessian.sendEmail(null, getMemberId(), 3);
		if(StringUtils.isBlank(token)){
			token = SerialNumberUtil.buildTokenSn();
			AppContext.setSessionAttr(token, true);
		}
		return Message.success(token);
	}
	
	/**
	 * 邮箱绑定验证
	 * @param code 验证码
	 * @return
	 */
	@RequestMapping("/validEmail/{code}")
	public String validEmail(@PathVariable String code, Model model){
		String email = memberHessian.verifyEmail(getMemberId(), code);
		String token = UUID.randomUUID().toString();
		AppContext.setSessionAttr(token, email);
		model.addAttribute("captchaId", token);
		return "/member/email/step2";
	}

	/**
	 * 修改邮箱
	 * @return
	 */
	@RequestMapping("/modifyEmail")
	public String modifyEmail(Model model){
		MemberBean member = getMember();
		if(StringUtils.isNotBlank(member.getEmail())){
			return "redirect:/member/validEmail.jhtml";
		}
		model.addAttribute("captchaId", UUID.randomUUID().toString());
		return "/member/email/step2";
	}
	
	/**
	 * 发送绑定邮件
	 * @param email
	 * @param request
	 * @param response
	 * @return
	 */
	@Validations(
			requiredStrings = {
					@RequiredStringValidator(fieldName="captchaId",message="验证码错误"),
					@RequiredStringValidator(fieldName="captcha",message="验证码错误"),
					@RequiredStringValidator(fieldName="email",message="电子邮箱错误")
			},
			specials = {
					@SpecialRegexFieldValidator(fieldName="email",fieldType=FieldType.email)
			}
	)
	@RequestMapping(value="/sendBindEmail",method=RequestMethod.POST)
	@ResponseBody
	public Message sendBindEmail(String captchaId, String captcha, String email){
		MemberBean member = getMember();
		if(AppContext.getSessionAttr(captchaId) == null){
			if(StringUtils.isNotBlank(member.getEmail())){
				throw new NoticeException("页面信息已过期");
			}
		}else{
			if(!AppContext.getSessionAttr(captchaId).toString().equals(member.getEmail())){
				throw new NoticeException("页面信息已过期");
			}
		}
		if(!captchaService.isValid(captchaId, captcha)){
			throw new NoticeException("验证码不正确");
		}
		ValueOperations<String, String> vo = redisTemplate.opsForValue();
		String sendEmail = vo.get(REDIS_BIND_EMAIL_PREFIX + getMemberId());
		if(StringUtils.isBlank(sendEmail) || !sendEmail.equals(email)){
			memberHessian.sendEmail(email, getMemberId(), 1);
			vo.set(REDIS_BIND_EMAIL_PREFIX + getMemberId(), email, EMAIL_RESEND_TIME, TimeUnit.SECONDS);
		}
		return successMessage;
	}
	
	/**
	 * 邮箱绑定验证
	 * @param code 验证码
	 * @return
	 */
	@RequestMapping("/verifyEmail/{code}")
	public String verifyEmail(@PathVariable String code){
		MemberBean member = jsonToObj(memberHessian.modifyEmail(code), MemberBean.class);
		AppContext.setSessionAttr("successMember", member);
		return "redirect:/member/email/success.jhtml";
	}

	/**
	 * 会员中心成功页面
	 * @param type 类型
	 * @return
	 */
	@RequestMapping("/{type}/success")
	public String success(@PathVariable String type){
		return "/member/" + type + "/success";
	}

	/**
	 * 手机验证页面
	 * @param model
	 * @return
	 */
	@RequestMapping("/mobile")
	public String mobile(Model model){
		model.addAttribute("captchaId", UUID.randomUUID().toString());
		model.addAttribute("member", getMember());
		return "/member/mobile/valid";
	}
	
	/**
	 * 发送验证短信
	 * @return
	 */
	@RequestMapping(value="/sendValidateSms",method=RequestMethod.POST)
	@ResponseBody
	public Message sendValidateSms(){
		JSONObject codeInfo = JSONObject.parseObject(memberHessian.sendMobileCaptcha(null, AppContext.getRemoteIp(), Boolean.TRUE, getMemberId(), 2));
		if(codeInfo.containsKey("error")){
			return Message.success(codeInfo.getString("error"));
		}
		return successMessage;
	}
	
	/**
	 * 验证手机验证码
	 * @param code 手机验证码
	 * @return
	 */
	@Validations(
			requiredStrings = {
					@RequiredStringValidator(fieldName="code",message="手机验证码错误"),
					@RequiredStringValidator(fieldName="captchaId",message="验证码错误"),
					@RequiredStringValidator(fieldName="captcha",message="验证码错误")
			}
	)
	@RequestMapping(value="/validateCode",method=RequestMethod.POST)
	public String validateCode(String code, String captchaId, String captcha, Model model, HttpServletRequest request, HttpServletResponse response){
		if(!captchaService.isValid(captchaId, captcha) && AppContext.getSessionAttr(captchaId) == null){
			model.addAttribute("captchaError", "验证码错误");
		}else{
			String error = memberHessian.validateCode(getMemberId(), code);
			if(StringUtils.isNotBlank(error)){
				AppContext.removeAttribute(captchaId);
				model.addAttribute("codeError", error);
			}else{
				AppContext.setSessionAttr(captchaId, true);
				return "/member/mobile/modify";
			}
		}
		model.addAttribute("captchaId", UUID.randomUUID().toString());
		model.addAttribute("member", getMember());
		return "/member/mobile/valid";
	}
	
	/**
	 * 发送换绑验证短信
	 * @param mobile 换绑手机号
	 * @return
	 */
	@RequestMapping(value="/sendBindSms",method=RequestMethod.POST)
	@ResponseBody
	public Message sendBindSms(String mobile){
		ValueOperations<String, String> vo = redisTemplate.opsForValue();
		String key = REDIS_BIND_SMS_PREFIX + mobile;
		long expiredTime = redisTemplate.getExpire(key);
		if(expiredTime > SMS_RESEND_TIME){
			return Message.error("请不要频繁发送验证码");
		}
		JSONObject codeInfo = JSONObject.parseObject(memberHessian.sendMobileCaptcha(mobile, AppContext.getRemoteIp(), Boolean.TRUE, null, 1));
		vo.set(key, codeInfo.getString("validateCode"), codeInfo.getLong("expired"), TimeUnit.MILLISECONDS);
		return successMessage;
	}
	
	/**
	 * 修改手机
	 * @param mobile 手机号码
	 * @param code 验证码
	 * @return
	 */
	@Validations(
			requiredStrings = {
					@RequiredStringValidator(fieldName="mobile",message="手机号码错误"),
					@RequiredStringValidator(fieldName="code",message="验证码不正确")
			},
			specials = {
					@SpecialRegexFieldValidator(fieldName="mobile",fieldType=FieldType.mobile)
			}
	)
	@RequestMapping(value="/modifyMobile",method=RequestMethod.POST)
	public String modifyMobile(String mobile, String code, Model model){
		ValueOperations<String, String> vo = redisTemplate.opsForValue();
		String validateCode = vo.get(REDIS_BIND_SMS_PREFIX + mobile);
		if(StringUtils.isBlank(validateCode)){
			throw new NoticeException("验证码已失效");
		}
		if(!validateCode.equals(code)){
			throw new NoticeException("验证码不正确");
		}
		try {
			memberHessian.modifyMobile(mobile, getMemberId());
		} catch (NoticeException e) {
			model.addAttribute("error", e.getMessage());
			return "/member/mobile/modify";
		}
		return "redirect:/member/safe.jhtml";
	}

	/**
	 * 我的评价列表
	 * @return
	 */
	@RequestMapping(value="/comment/list", method = RequestMethod.GET)
	public String comments(String orderNo, String commentsType, Integer pageNumber, Model model) {
		Boolean hasComment = null;
		if(StringUtils.isNotBlank(commentsType)) {
			if(commentsType.equals("all")) {
			} else if(commentsType.equals("yes")) {
				hasComment = true;
			} else if(commentsType.equals("no")) {
				hasComment = false;
			}
		}
		Pager pager = jsonToObj(commentHessian.getGoodsComments(getMemberId(), orderNo, hasComment, pageNumber, 10), Pager.class) ;
		model.addAttribute("orderNo", orderNo);
		model.addAttribute("commentsType", commentsType);
		model.addAttribute("pager", pager);
		return "/member/comments";
	}
	
	@Validations(
		requiredStrings = {
				@RequiredStringValidator(fieldName="orderItemId", message="订单项不能为空"),
				@RequiredStringValidator(fieldName="score", message="评分不能为空"),
				@RequiredStringValidator(fieldName="content", message="评价内容不能为空")
		},
		stringLengthFields = {
				@StringLengthFieldValidator(fieldName="content", minLength = "5", maxLength= "500", message="评价内容")
		}
	)
	@RequestMapping(value = "/comment", method=RequestMethod.POST)
	@ResponseBody
	public Message comment(Long orderItemId, Integer score, String content, Boolean anonymous) {
		commentHessian.comment(getMemberId(), orderItemId, score, content, anonymous, AppContext.getRemoteIp());
		return successMessage;
	}
	

	/**
	 * 咨询建议列表
	 * @param pageNumber
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/consult/list", method = RequestMethod.GET)
	public String consult(Integer pageNumber, Integer type, Model model){
		Pager pager = jsonToObj(memberExtendHessian.getConsultPagerData(
				getMemberId(), type, pageNumber, 10), Pager.class);
		model.addAttribute("pager", pager);
		model.addAttribute("type", type);
		return "/member/consult";
	}

	/**
	 * 提交咨询建议
	 * @param bean
	 * @param response
	 * @return
	 */
	@Validations(
			requiredStrings = {
					@RequiredStringValidator(fieldName="title",message="标题不能为空"),
					@RequiredStringValidator(fieldName="contact",message="联系电话不能为空"),
					@RequiredStringValidator(fieldName="type",message="类型不能为空"),
					@RequiredStringValidator(fieldName="content",message="内容不能为空"),

			},
			stringLengthFields = {
					@StringLengthFieldValidator(fieldName = "title", maxLength = "200", message = "标题长度必须在200以内!"),
					@StringLengthFieldValidator(fieldName = "content", maxLength = "200", minLength = "10", message = "内容长度必须在10到200之间!")
			},
			specials = {
					@SpecialRegexFieldValidator(fieldName="contact",fieldType=FieldType.mobileOrTelephone,message="手机号码格式不正确")
			}
	)
	@RequestMapping(value = "/consult", method = RequestMethod.POST)
	public String consult(ConsultBean bean, HttpServletResponse response){
		ConsultBean consult = jsonToObj(memberExtendHessian.saveConsultData(bean, getMemberId()), ConsultBean.class);
		JSONObject obj = new JSONObject();
		obj.put("data", consult);
		obj.put("status", successMessage);
		return ResponseUtils.renderJSON(obj, response);
	}

	/**
	 * 删除咨询建议
	 * @param response
	 * @return
	 */
	@Validations(
			requiredStrings = {
					@RequiredStringValidator(fieldName="consultId",message="该信息不存在"),
			}
	)
	@RequestMapping(value = "/consult/delete", method = RequestMethod.POST)
	public String delConsult(Long consultId, HttpServletResponse response){
		memberExtendHessian.deleteConsultData(new Long[]{consultId}, getMemberId());
		return ResponseUtils.renderJSON(successMessage, response);
	}


	/**
	 * 到货通知
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/stocknotice/list", method = RequestMethod.GET)
	public String stocknoticeList(Integer pageNumber, Model model){
		Pager pager = jsonToObj(memberExtendHessian.getStockNoticePageData(getMemberId(), pageNumber, 10),
				Pager.class);
		model.addAttribute("pager", pager);
		return "/member/stocknotice";
	}

	/**
	 * 删除到货通知
	 * @param id
	 * @param response
	 * @return
	 */
	@Validations(
			requiredStrings = {
					@RequiredStringValidator(fieldName="id",message="该信息不存在"),
			}
	)
	@RequestMapping(value = "/stocknotice/delete")
	public String delStocknotice(Long id, HttpServletResponse response){
		memberExtendHessian.deleteStockNotice(new Long[]{id}, getMemberId());
		return ResponseUtils.renderJSON(successMessage, response);
	}


	/**
	 * 到货通知
	 * @param goodsId
	 * @param quantity
	 * @param memo
	 * @param response
	 * @return
	 */
	@Validations(
			requiredStrings = {
					@RequiredStringValidator(fieldName="goodsId",message="商品不存在"),
			}
	)
	@RequestMapping(value = "/stocknotice/register", method = RequestMethod.POST)
	public String stocknotice(Long goodsId, Integer quantity, String memo, HttpServletResponse response){
		memberExtendHessian.saveStockNotice(goodsId, quantity, memo, getMemberId());
		return ResponseUtils.renderJSON(successMessage, response);
	}

	/**
	 * 站内通知
	 * @return
	 */
	@RequestMapping(value = "/sitenotice/list", method = RequestMethod.GET)
	public String sitenotice(Integer pageNumber, Model model){
		Pager pager = jsonToObj(memberExtendHessian.getSiteNoticePageData(getMemberId(), pageNumber, 10), Pager.class);
		model.addAttribute("pager", pager);
		return "/member/sitenotice";
	}

	/**
	 * 站内通知
	 * @return
	 */
	@Validations(
			requiredStrings = {
					@RequiredStringValidator(fieldName="id",message="该通知不存在"),
			}
	)
	@RequestMapping(value = "/sitenotice/detail", method = RequestMethod.GET)
	public String sitenoticeDetail(Long id, Model model){
		SiteNoticeBean siteNoticeBean = jsonToObj(memberExtendHessian.getSiteNoticeData(id, getMemberId()), SiteNoticeBean.class);
		model.addAttribute("content", siteNoticeBean.getContent());
		model.addAttribute("title", siteNoticeBean.getTitle());
		return "/member/sitenotice-detail";
	}


	/**
	 * 删除站内通知
	 * @param id
	 * @param response
	 * @return
	 */
	@Validations(
		requiredStrings = {
				@RequiredStringValidator(fieldName="id",message="该通知不存在"),
		}
	)
	@RequestMapping(value = "/sitenotice/delete")
	public String delSitenotice(Long id, HttpServletResponse response){
		memberExtendHessian.deleteSiteNotice(new Long[]{id}, getMemberId());
		return ResponseUtils.renderJSON(successMessage, response);
	}

	/**
	 * 是否有邮箱
	 * @return
	 */
	@RequestMapping("/hasEmail")
	@ResponseBody
	public Boolean hasEmail(){
		MemberBean member = getMember();
		if(member == null){
			throw new NoticeException("帐号不存在");
		}
		return  StringUtils.isNotBlank(member.getEmail());
	}

	@RequestMapping("/firends")
	public String queryFirends(Model model){
		List<FirendBean> list = jsonToList(memberHessian.findFriends(getMemberId()), FirendBean.class);
		model.addAttribute("firends", list);
		return "/member/firends";
	}

	@RequestMapping("/intergral/logs")
	public String queryIntergralLogs(Integer pageNumber,Model model){
		Pager pager  = jsonToObj(intergralHession.getIntergralLogList(getMemberId(), pageNumber), Pager.class);
		model.addAttribute("pager", pager);
		return "/member/intergrallogs";
	}
}
